<?php
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
class Adminlanguage_model extends  Model {

    function __construct()
    {
        // Call the Model constructor
        parent::__construct();
    }

    function getLanguageDetails()
    {
        //$sql = "SELECT DISTINCT a.keytext as keytext, a.section, a.id, (SELECT b.lvalue FROM tbl_labels b WHERE b.lang='en' AND b.keytext=a.keytext ) AS en ,(SELECT b.lvalue FROM tbl_labels b WHERE b.lang='de' AND b.keytext=a.keytext) AS de
        $sql = "SELECT DISTINCT
                  `a`.`keytext` AS `keytext`,
                  `a`.`section` AS `section`,
                  (SELECT
                     `b`.`id`      AS `id`
                   FROM `tbl_labels` `b`
                   WHERE ((`b`.`lang` = 'en')
                          AND (`b`.`keytext` = `a`.`keytext`))) AS `en_id`,
                  (SELECT
                     `b`.`id`      AS `id`
                   FROM `tbl_labels` `b`
                   WHERE ((`b`.`lang` = 'de')
                          AND (`b`.`keytext` = `a`.`keytext`))) AS `de_id`,
                  (SELECT
                     `b`.`lvalue`  AS `lvalue`
                   FROM `tbl_labels` `b`
                   WHERE ((`b`.`lang` = 'en')
                          AND (`b`.`keytext` = `a`.`keytext`))) AS `en`,
                  (SELECT
                     `b`.`lvalue`  AS `lvalue`
                   FROM `tbl_labels` `b`
                   WHERE ((`b`.`lang` = 'de')
                          AND (`b`.`keytext` = `a`.`keytext`))) AS `de`
                FROM `tbl_labels` `a`";
               
        $langlbl_qry = $this->db->query($sql);
        $langlbl_arr = $langlbl_qry->result_array();

        return $langlbl_arr;
    }

    function getLabelByLang($id, $lang)
    {
        echo $sql = "SELECT lvalue FROM tbl_labels WHERE id = " . $id . " AND lang='" . $lang . "' ";
        $langlbl_qry = $this->db->query($sql);
        //$langlbl_arr = $langlbl_qry->result_array();

        return $langlbl_qry->result();
    }

    function updateLabels($post_arr)
    {
        $id = $post_arr['txtId'];
        $label_val = str_replace("<p>", "<p>%", $post_arr['lblval']);
        $lang = $post_arr['txtLang'];
        
        $sql = "UPDATE tbl_labels
                SET lvalue = '" . $label_val . "'
                WHERE id = '" . $id . "' AND lang = '" . $lang . "' ";
        $this->db->query($sql);
    }
}
?>
